<template>
    <div>
  <h1>{{msg}}</h1>
  <h2>{{list}}</h2>
    <div v-for="(listone,index) in list">
        {{listone.name}}--{{index}}
    </div>
  </div>
</template>

<script>

import Axios from 'axios'
export default {
    name:"hell" ,
    data(){ //这里提示要data函数不能是data:{}
       return {
           msg: 1,
           list:[]
       } 
    },
    mounted (){
        //debugger
        console.log("页面渲染之后执行！")
    },
    created (){
        //debugger
        console.log("页面渲染之前执行！")
        this.getData()
        this.getData1()
        
        //this.list=this.getData()//这样写不行，不会得到getData中的数据，created方法没加载之前就执行了，方法要写到getData中
        //console.log(this.list)
    },
    methods:{
        getData(){
            Axios.get("http://localhost:8080/static/mock/data.json")
                .then(data => {
                   console.log(data)
                    // return data
                    this.list=data.data.data.data
                    return data.data

                })
                .catch(error =>{
                })
        },
        getData1(){
            this.$http.get("s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=前端返回promise&oq=%25E5%2593%2594%25E5%2593%25A9%25E5%2593%2594%25E5%2593%25A9&rsv_pq=d9e71b200008dbd9&rsv_t=f209UTcgQ2vcz3F5dCBcqStKSImnMxChn%2B2TpPC8CS5spalBpve3%2FoLKHeo&rqlang=cn&rsv_enter=1&rsv_dl=tb&rsv_btype=t&inputT=11248&rsv_sug3=79&rsv_sug1=62&rsv_sug7=100&rsv_sug2=0&rsv_sug4=11248")
                .then(data =>{
                    console.log(data)
                })
                .catch(error =>{
                    console.log(error)
                    this.$message({
                        message: '恭喜你，这是一条成功消息',
                        type: 'success'
                    })
                    this.$message.error("这是一条错误的消息！")
                    const sessionId = window.localStorage.getItem('sessionId') || '';
                    
                })
        }
    }

}
</script>

<style lang="less" scoped>

</style>